Few questions after watching django tutorials

by: luka9x, 9 years ago

Last edited: 9 years ago

Hi everyone I've finished watching all 12 django tutorials and I got few questions.

1. Why do we define __str__(self) so it can return an actual string and how does that python django magic work? When and how does it get called and why do we have it only for title?

2.I looked at django docs and I made a small app that when you go to /admin/another_admin_app just adds an entry to the database and redirects you back to home page. I want to expand that app so it scrapes data from web (using some API), then it adds it to database and then redirects you back to home page. So far I used "views.py" to write my code for adding entry to db table, so when I want to make the full scraping program, should I just shove it all inside that views.py file ? Aaand is there more to it if I want to do something like that or is that it?

3. So I made the app that only I should access. So is it enough that I linked the " /admin/another_admin_app " in main urls.py to the app's urls.py and then from that one, to views.py, where the app code executes and redirects me back to home page. Only I can access that app because in order to access it I need to login first to /admin, right ?

4. What is the most efficient way of splitting data from database, into pages (for example limited to 20 entries per page)

Sorry if I'm not clear enough about some question but it's 7 AM and I was doing django and python all night :D



You must be logged in to post. Please login or register an account.



1. That's just something that is fundamentally a part of OOP. OOP is a form of programming where you create classes that return objects. Objects have attributes that you define. In order for that object to have a string attribute, you have to give the class a method that allows for it.

2. You shouldn't stuff it into views, but rather have a new python file that does all of that stuff in a function and you simply import and call it in views.

3. If you want to hide it behind admin, that should be fine.

4. Search "pagination with django," or something along those lines in Google. This typically involves both HTML/CSS and logic to make happen.

-Harrison 9 years ago

You must be logged in to post. Please login or register an account.


Thanks a lot, I did the django tutorial also, and I already started working on a project and I got the hang of it all, docs are awesome.
Pagination became clear when I finished the official tutorial and started playing around.

I just have one problem and that's working with pictures, here's a link to post I made here if you have time.
https://pythonprogramming.net/community/155/Problem%20with%20pictures%20-%20ImageField%20and%20calling%20it/

Thanks a lot again !

-luka9x 9 years ago
Last edited 9 years ago

You must be logged in to post. Please login or register an account.